//
//  NetConnect.m
//  groupProject
//
//  Created by mac on 15/12/28.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "NetConnect.h"
#import "AFHTTPRequestOperationManager.h"
#import "Config.h"
#import "DataModel.h"

@implementation NetConnect
@synthesize datamodel;



- (void) firstConnect {
    AFHTTPRequestOperationManager *manage = [[AFHTTPRequestOperationManager alloc] init];
    //post 方式请求响应
    //第一个参数 post的url对应的string
    //第二个参数 http的body
    [manage POST:ZM_SERVER parameters:ZM_BOBY success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //连接成功 responseObject为返回的数据  可以对此数据进行解析了
        //在datamodel中完成解析
        NSLog(@"connect sucessed!");
        NSLog(@"获得响应");
        datamodel =[[DataModel alloc] init];
        [datamodel decodeResponseObject:(NSDictionary *)responseObject];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"connect failed!");
    }];
}

- (DataModel *) datamodel {
    if (datamodel == nil) {
        datamodel =[[DataModel alloc] init];
    }
    return datamodel;
}

@end
